/**
 * 
 */
package jvs.vfs.link;

import java.io.FileFilter;
import java.io.FilenameFilter;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;

import jvs.vfs.FileSystem;
import jvs.vfs.IFile;
import x.java.io.File;

/**
 * @author qiangli
 *
 */
public class LinkFileImpl implements IFile {
	private static final FileSystem fs = FileSystem.getFileSystem();
	private static final int LINK_EXT_LEN = File.LINK_EXT.length();
	
	private IFile ifile;

	public LinkFileImpl(URI uri) throws Exception {
		String s = uri.toString();
		int idx = s.indexOf(":");
		String delegate = s.substring(idx+1);
		//
		ifile = fs.createIFile(new URI(delegate));
	}

	public boolean canExecute() {
		return ifile.canExecute();
	}

	public boolean canRead() {
		return ifile.canRead();
	}

	public boolean canWrite() {
		return ifile.canWrite();
	}

	public boolean copy(URI uri) {
		return ifile.copy(uri);
	}

	public boolean create() {
		return false;
	}

	public boolean delete() {
		return false;
	}

	public void deleteOnExit() {
		//
	}

	public boolean execute() {
		return ifile.execute();
	}

	public boolean exists() {
		return ifile.exists();
	}

	public Object getAttribute(String name) {
		return ifile.getAttribute(name);
	}

	public String getContent() {
		return ifile.getContent();
	}

	public String getContentEncoding() {
		return ifile.getContentEncoding();
	}

	public String getContentType() {
		return ifile.getContentType();
	}

	public String getDisplayName() {
		String n = ifile.getDisplayName();
		if (n.endsWith(File.LINK_EXT)) {
			int len = n.length();
			n = n.substring(0, len - LINK_EXT_LEN);
		}
		return n;
	}

	public Object getIcon() {
		return ifile.getIcon();
	}

	public InputStream getInputStream() {
		return ifile.getInputStream();
	}

	public long getLastModified() {
		return ifile.getLastModified();
	}

	public long getLength() {
		return ifile.getLength();
	}

	public String getName() {
		return ifile.getName();
	}

	public OutputStream getOutputStream() {
		return ifile.getOutputStream();
	}

	public OutputStream getOutputStream(boolean append) {
		return ifile.getOutputStream(append);
	}

	public String getPhoneticName() {
		return ifile.getPhoneticName();
	}

	public String getSortKey() {
		return ifile.getSortKey();
	}

	public boolean isDirectory() {
		return ifile.isDirectory();
	}

	public boolean isEmpty() {
		return ifile.isEmpty();
	}

	public boolean isFile() {
		return ifile.isFile();
	}

	public boolean isLocal() {
		return ifile.isLocal();
	}

	public boolean isNative() {
		return ifile.isNative();
	}

	public String[] list() {
		return ifile.list();
	}

	public String[] list(int off, int max) {
		return ifile.list(off, max);
	}

	public IFile[] listFiles() {
		return ifile.listFiles();
	}

	public IFile[] listFiles(FileFilter filter) {
		return ifile.listFiles(filter);
	}

	public IFile[] listFiles(FilenameFilter filter) {
		return ifile.listFiles(filter);
	}

	public IFile[] listFiles(int off, int max) {
		return ifile.listFiles(off, max);
	}

	public boolean mkdir() {
		//is link
		return false;
	}

	public boolean move(URI uri) {
		//move in File
		return false;
	}

	public void refresh() {
		ifile.refresh();
	}

	public boolean setAttribute(String name, Object value) {
		return ifile.setAttribute(name, value);
	}

	public boolean setContent(String s) {
		return ifile.setContent(s);
	}

	public boolean setContentEncoding(String encoding) {
		return ifile.setContentEncoding(encoding);
	}

	public boolean setContentType(String mimeType) {
		return ifile.setContentType(mimeType);
	}

	public boolean setInputStream(InputStream in) {
		return ifile.setInputStream(in);
	}

	public boolean setLastModified(long time) {
		return ifile.setLastModified(time);
	}

	public boolean setLength(long len) {
		return ifile.setLength(len);
	}

	public boolean setOutputStream(OutputStream out) {
		return ifile.setOutputStream(out);
	}

	public URI toRealURI() {
		return ifile.toRealURI();
	}
}
